package utils;

import cn.hutool.core.util.IdUtil;
import com.secret.pictureApplication;
import io.swagger.annotations.ApiModelProperty;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
/**
 * @author 曹见朋
 * @create 2023-10-23-10:02
 */
@SpringBootTest(classes = {pictureApplication.class})
public class FileBatchRename {
    @Test
    @ApiModelProperty("测试数据文件重命名")
    public  void main() {
        List<String> mysql=new ArrayList<>();
        // 设置目录路径
        String directoryPath = "D:\\资源文件\\ps\\项目文件夹\\焰灵姬";
        // 构建文件路径
        Path directory = Paths.get(directoryPath);
        try {
            // 获取目录下的所有文件
            Stream<Path> files = Files.list(directory);

            // 遍历所有文件并重命名
            files.forEach(file -> {
                try {
                    // 获取文件的名称
                    String fileName = file.getFileName().toString();
                    // 新的文件名（可以按需修改）
                    String uuid = IdUtil.simpleUUID();
                    String newFileName = uuid+".png";
                    // 构建新文件路径
                    Path newFilePath = directory.resolve(newFileName);
                    // 执行文件重命名
                    Files.move(file, newFilePath, StandardCopyOption.REPLACE_EXISTING);
                    mysql.add(newFileName);
                    System.out.println(newFileName);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            System.out.println("=========================================");
            String m="";
            for (int i = 0; i < mysql.size(); i++) {
                if (i<5){
                    m=m+"('"+mysql.get(i)+"',"+"0173"+","+i*20+"),";
                }else
                if (5<i&&i<=10){
                    m=m+"('"+mysql.get(i)+"',"+"0174"+","+i*20+"),";
                }else
                if (10<i&&i<=15){
                    m=m+"('"+mysql.get(i)+"',"+"0175"+","+i*20+"),";
                }else {
                    m=m+"('"+mysql.get(i)+"',"+"0172"+","+i*20+"),";
                }
            }
            System.out.println(m);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

